<?php
include( "admin/now5_header.php" );
$percent = 0;
$lostwin = array();
$betcount = array();
$totalamount = array();
$list = array("", "", "", "", "", "", "", "", "", "");
$bettype = 11;
$rowNum = 20;
$colNum = 10;
$tot = $rowNum * $colNum;
$totalamount[$bettype] = 0;
$betcount[$bettype] = 0;
$betTypeStr = "";
switch ($bettype)
{
    case 9 :
        $betTypeStr = "bettype IN ( 9,33)";
        break;
    case 10 :
        $betTypeStr = "bettype IN (10,32)";
        break;
    default :
        $betTypeStr = "bettype=" . $bettype;
        break;
}
$sql = " sum(totalAmt) as totalAmt FROM (\r\n  Select line_nums,(unitmoney*upercent/100) as totalAmt\r\n  from bet where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(unitmoney*percent255/100) as totalAmt\r\n  from bet2 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(amount*-1) as totalAmt\r\n  from bet8 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  ) A";
$rs1 = getdb("SELECT " . $sql);
$rs2 = getdb("Select line_nums," . $sql . " GROUP BY line_nums Order by totalAmt desc LIMIT " . $tot);
$totalamount[$bettype] = round($rs1->f[0], 0);
if ($totalamount[$bettype] != 0)
{
    $col = 0;
    $recc = 0;
    while (!$rs2->eof)
    {
        $c = $rs2->f[0];
        $n = round($rs2->f[1], 0);
        if ($recc == 0)
        {
            $list[$col] = "<table border=0 width=88% cellspacing=0 cellpadding=0>";
        }
        if ($c != "" && $n != 0)
        {
            $list .= $col;
            $list .= $col;
            $list .= $col;
        }
        if ($rowNum - 1 <= $recc)
        {
            $list .= $col;
            ++$col;
            $recc = 0;
        }
        else
        {
            ++$recc;
        }
        $rs2->movenext();
    }
    if (0 < $recc && $recc < $rowNum - 1)
    {
        $list .= $col;
    }
}
$rs1->close();
$rs2->close();
$rs = getdb("select * from rate5a where lotto_id=" . $lotto_id);
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$tpl->set("r11_1", $rs->f['r11_1']);
$i = 0;
while ($i < 10)
{
    $tpl->set("list" . $i, $list[$i]);
    ++$i;
}
$tpl->set("totall", "显示排行前 <b>" . $tot . "</b> 笔，合计金额：<b>" . $totalamount[11] . "</b>");
$tpl->load("main", "now5_11.htm");
$tpl->set("jslang", $g_conf['language']);
$tpl->show("main");
$ui->footer();
?>